<?php
include_once "conn.php";
$id=$_GET['id'];
$sql=$db->query("SELECT address_default FROM address WHERE address_default = 1 AND user_id = 
                (SELECT user_id FROM address WHERE address_id = '$id')");
if($sql->num_rows > 0){
    $res1=$db->query("UPDATE address SET address_default = 0 WHERE address_default = 1 AND user_id = 
        (SELECT user_id FROM (SELECT user_id FROM address AS t1 WHERE address_id = '$id')AS t2)");
    $res2=$db->query("UPDATE address SET address_default = 1 WHERE address_id = '$id'");
}else{
    $res=$db->query("UPDATE address SET address_default = 1 WHERE address_id = '$id'");
}
$db->close();
?>